package com.yzcity.cinema.web.rest;

import com.yzcity.cinema.RedisTestContainerExtension;
import com.yzcity.cinema.YzcitycinemaApp;
import com.yzcity.cinema.domain.Actor;
import com.yzcity.cinema.repository.ActorRepository;
import com.yzcity.cinema.service.ActorService;
import com.yzcity.cinema.service.dto.ActorDTO;
import com.yzcity.cinema.service.mapper.ActorMapper;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.time.LocalDate;
import java.time.Instant;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link ActorResource} REST controller.
 */
@SpringBootTest(classes = YzcitycinemaApp.class)
@ExtendWith({ RedisTestContainerExtension.class, MockitoExtension.class })
@AutoConfigureMockMvc
@WithMockUser
public class ActorResourceIT {

    private static final String DEFAULT_CNAME = "AAAAAAAAAA";
    private static final String UPDATED_CNAME = "BBBBBBBBBB";

    private static final String DEFAULT_ENAME = "AAAAAAAAAA";
    private static final String UPDATED_ENAME = "BBBBBBBBBB";

    private static final String DEFAULT_ALIAS = "AAAAAAAAAA";
    private static final String UPDATED_ALIAS = "BBBBBBBBBB";

    private static final String DEFAULT_ROLE = "AAAAAAAAAA";
    private static final String UPDATED_ROLE = "BBBBBBBBBB";

    private static final String DEFAULT_LABEL = "AAAAAAAAAA";
    private static final String UPDATED_LABEL = "BBBBBBBBBB";

    private static final LocalDate DEFAULT_BIRTHDAY = LocalDate.ofEpochDay(0L);
    private static final LocalDate UPDATED_BIRTHDAY = LocalDate.now(ZoneId.systemDefault());

    private static final String DEFAULT_BIRTH_SITE = "AAAAAAAAAA";
    private static final String UPDATED_BIRTH_SITE = "BBBBBBBBBB";

    private static final String DEFAULT_IDENTITY = "AAAAAAAAAA";
    private static final String UPDATED_IDENTITY = "BBBBBBBBBB";

    private static final String DEFAULT_GENDER = "AAAAAAAAAA";
    private static final String UPDATED_GENDER = "BBBBBBBBBB";

    private static final String DEFAULT_NATIONALITY = "AAAAAAAAAA";
    private static final String UPDATED_NATIONALITY = "BBBBBBBBBB";

    private static final String DEFAULT_HEIGHT = "AAAAAAAAAA";
    private static final String UPDATED_HEIGHT = "BBBBBBBBBB";

    private static final Long DEFAULT_BLOOD_TYPE = 1L;
    private static final Long UPDATED_BLOOD_TYPE = 2L;

    private static final String DEFAULT_CONSTELLATION = "AAAAAAAAAA";
    private static final String UPDATED_CONSTELLATION = "BBBBBBBBBB";

    private static final String DEFAULT_GRADUATED_FOR = "AAAAAAAAAA";
    private static final String UPDATED_GRADUATED_FOR = "BBBBBBBBBB";

    private static final String DEFAULT_RANK = "AAAAAAAAAA";
    private static final String UPDATED_RANK = "BBBBBBBBBB";

    private static final Integer DEFAULT_FANS_COUNT = 1;
    private static final Integer UPDATED_FANS_COUNT = 2;

    private static final String DEFAULT_FANS_NAME = "AAAAAAAAAA";
    private static final String UPDATED_FANS_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_BROKERAGE_AGENCY = "AAAAAAAAAA";
    private static final String UPDATED_BROKERAGE_AGENCY = "BBBBBBBBBB";

    private static final String DEFAULT_CREATED_BY = "AAAAAAAAAA";
    private static final String UPDATED_CREATED_BY = "BBBBBBBBBB";

    private static final Instant DEFAULT_CREATED_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_CREATED_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final String DEFAULT_LAST_MODIFIED_BY = "AAAAAAAAAA";
    private static final String UPDATED_LAST_MODIFIED_BY = "BBBBBBBBBB";

    private static final Instant DEFAULT_LAST_MODIFIED_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_LAST_MODIFIED_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    @Autowired
    private ActorRepository actorRepository;

    @Autowired
    private ActorMapper actorMapper;

    @Autowired
    private ActorService actorService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restActorMockMvc;

    private Actor actor;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static Actor createEntity(EntityManager em) {
        Actor actor = new Actor()
            .cname(DEFAULT_CNAME)
            .ename(DEFAULT_ENAME)
            .alias(DEFAULT_ALIAS)
            .role(DEFAULT_ROLE)
            .label(DEFAULT_LABEL)
            .birthday(DEFAULT_BIRTHDAY)
            .birthSite(DEFAULT_BIRTH_SITE)
            .identity(DEFAULT_IDENTITY)
            .gender(DEFAULT_GENDER)
            .nationality(DEFAULT_NATIONALITY)
            .height(DEFAULT_HEIGHT)
            .bloodType(DEFAULT_BLOOD_TYPE)
            .constellation(DEFAULT_CONSTELLATION)
            .graduatedFor(DEFAULT_GRADUATED_FOR)
            .rank(DEFAULT_RANK)
            .fansCount(DEFAULT_FANS_COUNT)
            .fansName(DEFAULT_FANS_NAME)
            .brokerageAgency(DEFAULT_BROKERAGE_AGENCY)
            .createdBy(DEFAULT_CREATED_BY)
            .createdTime(DEFAULT_CREATED_TIME)
            .lastModifiedBy(DEFAULT_LAST_MODIFIED_BY)
            .lastModifiedTime(DEFAULT_LAST_MODIFIED_TIME);
        return actor;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static Actor createUpdatedEntity(EntityManager em) {
        Actor actor = new Actor()
            .cname(UPDATED_CNAME)
            .ename(UPDATED_ENAME)
            .alias(UPDATED_ALIAS)
            .role(UPDATED_ROLE)
            .label(UPDATED_LABEL)
            .birthday(UPDATED_BIRTHDAY)
            .birthSite(UPDATED_BIRTH_SITE)
            .identity(UPDATED_IDENTITY)
            .gender(UPDATED_GENDER)
            .nationality(UPDATED_NATIONALITY)
            .height(UPDATED_HEIGHT)
            .bloodType(UPDATED_BLOOD_TYPE)
            .constellation(UPDATED_CONSTELLATION)
            .graduatedFor(UPDATED_GRADUATED_FOR)
            .rank(UPDATED_RANK)
            .fansCount(UPDATED_FANS_COUNT)
            .fansName(UPDATED_FANS_NAME)
            .brokerageAgency(UPDATED_BROKERAGE_AGENCY)
            .createdBy(UPDATED_CREATED_BY)
            .createdTime(UPDATED_CREATED_TIME)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY)
            .lastModifiedTime(UPDATED_LAST_MODIFIED_TIME);
        return actor;
    }

    @BeforeEach
    public void initTest() {
        actor = createEntity(em);
    }

    @Test
    @Transactional
    public void createActor() throws Exception {
        int databaseSizeBeforeCreate = actorRepository.findAll().size();
        // Create the Actor
        ActorDTO actorDTO = actorMapper.toDto(actor);
        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isCreated());

        // Validate the Actor in the database
        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeCreate + 1);
        Actor testActor = actorList.get(actorList.size() - 1);
        assertThat(testActor.getCname()).isEqualTo(DEFAULT_CNAME);
        assertThat(testActor.getEname()).isEqualTo(DEFAULT_ENAME);
        assertThat(testActor.getAlias()).isEqualTo(DEFAULT_ALIAS);
        assertThat(testActor.getRole()).isEqualTo(DEFAULT_ROLE);
        assertThat(testActor.getLabel()).isEqualTo(DEFAULT_LABEL);
        assertThat(testActor.getBirthday()).isEqualTo(DEFAULT_BIRTHDAY);
        assertThat(testActor.getBirthSite()).isEqualTo(DEFAULT_BIRTH_SITE);
        assertThat(testActor.getIdentity()).isEqualTo(DEFAULT_IDENTITY);
        assertThat(testActor.getGender()).isEqualTo(DEFAULT_GENDER);
        assertThat(testActor.getNationality()).isEqualTo(DEFAULT_NATIONALITY);
        assertThat(testActor.getHeight()).isEqualTo(DEFAULT_HEIGHT);
        assertThat(testActor.getBloodType()).isEqualTo(DEFAULT_BLOOD_TYPE);
        assertThat(testActor.getConstellation()).isEqualTo(DEFAULT_CONSTELLATION);
        assertThat(testActor.getGraduatedFor()).isEqualTo(DEFAULT_GRADUATED_FOR);
        assertThat(testActor.getRank()).isEqualTo(DEFAULT_RANK);
        assertThat(testActor.getFansCount()).isEqualTo(DEFAULT_FANS_COUNT);
        assertThat(testActor.getFansName()).isEqualTo(DEFAULT_FANS_NAME);
        assertThat(testActor.getBrokerageAgency()).isEqualTo(DEFAULT_BROKERAGE_AGENCY);
        assertThat(testActor.getCreatedBy()).isEqualTo(DEFAULT_CREATED_BY);
        assertThat(testActor.getCreatedTime()).isEqualTo(DEFAULT_CREATED_TIME);
        assertThat(testActor.getLastModifiedBy()).isEqualTo(DEFAULT_LAST_MODIFIED_BY);
        assertThat(testActor.getLastModifiedTime()).isEqualTo(DEFAULT_LAST_MODIFIED_TIME);
    }

    @Test
    @Transactional
    public void createActorWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = actorRepository.findAll().size();

        // Create the Actor with an existing ID
        actor.setId(1L);
        ActorDTO actorDTO = actorMapper.toDto(actor);

        // An entity with an existing ID cannot be created, so this API call must fail
        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        // Validate the Actor in the database
        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkCnameIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setCname(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkEnameIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setEname(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkAliasIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setAlias(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkRoleIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setRole(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkLabelIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setLabel(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkBirthdayIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setBirthday(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkBirthSiteIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setBirthSite(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkIdentityIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setIdentity(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkGenderIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setGender(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkNationalityIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setNationality(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkHeightIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setHeight(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkBloodTypeIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setBloodType(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkConstellationIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setConstellation(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkGraduatedForIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setGraduatedFor(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkRankIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setRank(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkFansCountIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setFansCount(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkFansNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setFansName(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkBrokerageAgencyIsRequired() throws Exception {
        int databaseSizeBeforeTest = actorRepository.findAll().size();
        // set the field null
        actor.setBrokerageAgency(null);

        // Create the Actor, which fails.
        ActorDTO actorDTO = actorMapper.toDto(actor);


        restActorMockMvc.perform(post("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllActors() throws Exception {
        // Initialize the database
        actorRepository.saveAndFlush(actor);

        // Get all the actorList
        restActorMockMvc.perform(get("/api/actors?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(actor.getId().intValue())))
            .andExpect(jsonPath("$.[*].cname").value(hasItem(DEFAULT_CNAME)))
            .andExpect(jsonPath("$.[*].ename").value(hasItem(DEFAULT_ENAME)))
            .andExpect(jsonPath("$.[*].alias").value(hasItem(DEFAULT_ALIAS)))
            .andExpect(jsonPath("$.[*].role").value(hasItem(DEFAULT_ROLE)))
            .andExpect(jsonPath("$.[*].label").value(hasItem(DEFAULT_LABEL)))
            .andExpect(jsonPath("$.[*].birthday").value(hasItem(DEFAULT_BIRTHDAY.toString())))
            .andExpect(jsonPath("$.[*].birthSite").value(hasItem(DEFAULT_BIRTH_SITE)))
            .andExpect(jsonPath("$.[*].identity").value(hasItem(DEFAULT_IDENTITY)))
            .andExpect(jsonPath("$.[*].gender").value(hasItem(DEFAULT_GENDER)))
            .andExpect(jsonPath("$.[*].nationality").value(hasItem(DEFAULT_NATIONALITY)))
            .andExpect(jsonPath("$.[*].height").value(hasItem(DEFAULT_HEIGHT)))
            .andExpect(jsonPath("$.[*].bloodType").value(hasItem(DEFAULT_BLOOD_TYPE.intValue())))
            .andExpect(jsonPath("$.[*].constellation").value(hasItem(DEFAULT_CONSTELLATION)))
            .andExpect(jsonPath("$.[*].graduatedFor").value(hasItem(DEFAULT_GRADUATED_FOR)))
            .andExpect(jsonPath("$.[*].rank").value(hasItem(DEFAULT_RANK)))
            .andExpect(jsonPath("$.[*].fansCount").value(hasItem(DEFAULT_FANS_COUNT)))
            .andExpect(jsonPath("$.[*].fansName").value(hasItem(DEFAULT_FANS_NAME)))
            .andExpect(jsonPath("$.[*].brokerageAgency").value(hasItem(DEFAULT_BROKERAGE_AGENCY)))
            .andExpect(jsonPath("$.[*].createdBy").value(hasItem(DEFAULT_CREATED_BY)))
            .andExpect(jsonPath("$.[*].createdTime").value(hasItem(DEFAULT_CREATED_TIME.toString())))
            .andExpect(jsonPath("$.[*].lastModifiedBy").value(hasItem(DEFAULT_LAST_MODIFIED_BY)))
            .andExpect(jsonPath("$.[*].lastModifiedTime").value(hasItem(DEFAULT_LAST_MODIFIED_TIME.toString())));
    }
    
    @Test
    @Transactional
    public void getActor() throws Exception {
        // Initialize the database
        actorRepository.saveAndFlush(actor);

        // Get the actor
        restActorMockMvc.perform(get("/api/actors/{id}", actor.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(actor.getId().intValue()))
            .andExpect(jsonPath("$.cname").value(DEFAULT_CNAME))
            .andExpect(jsonPath("$.ename").value(DEFAULT_ENAME))
            .andExpect(jsonPath("$.alias").value(DEFAULT_ALIAS))
            .andExpect(jsonPath("$.role").value(DEFAULT_ROLE))
            .andExpect(jsonPath("$.label").value(DEFAULT_LABEL))
            .andExpect(jsonPath("$.birthday").value(DEFAULT_BIRTHDAY.toString()))
            .andExpect(jsonPath("$.birthSite").value(DEFAULT_BIRTH_SITE))
            .andExpect(jsonPath("$.identity").value(DEFAULT_IDENTITY))
            .andExpect(jsonPath("$.gender").value(DEFAULT_GENDER))
            .andExpect(jsonPath("$.nationality").value(DEFAULT_NATIONALITY))
            .andExpect(jsonPath("$.height").value(DEFAULT_HEIGHT))
            .andExpect(jsonPath("$.bloodType").value(DEFAULT_BLOOD_TYPE.intValue()))
            .andExpect(jsonPath("$.constellation").value(DEFAULT_CONSTELLATION))
            .andExpect(jsonPath("$.graduatedFor").value(DEFAULT_GRADUATED_FOR))
            .andExpect(jsonPath("$.rank").value(DEFAULT_RANK))
            .andExpect(jsonPath("$.fansCount").value(DEFAULT_FANS_COUNT))
            .andExpect(jsonPath("$.fansName").value(DEFAULT_FANS_NAME))
            .andExpect(jsonPath("$.brokerageAgency").value(DEFAULT_BROKERAGE_AGENCY))
            .andExpect(jsonPath("$.createdBy").value(DEFAULT_CREATED_BY))
            .andExpect(jsonPath("$.createdTime").value(DEFAULT_CREATED_TIME.toString()))
            .andExpect(jsonPath("$.lastModifiedBy").value(DEFAULT_LAST_MODIFIED_BY))
            .andExpect(jsonPath("$.lastModifiedTime").value(DEFAULT_LAST_MODIFIED_TIME.toString()));
    }
    @Test
    @Transactional
    public void getNonExistingActor() throws Exception {
        // Get the actor
        restActorMockMvc.perform(get("/api/actors/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateActor() throws Exception {
        // Initialize the database
        actorRepository.saveAndFlush(actor);

        int databaseSizeBeforeUpdate = actorRepository.findAll().size();

        // Update the actor
        Actor updatedActor = actorRepository.findById(actor.getId()).get();
        // Disconnect from session so that the updates on updatedActor are not directly saved in db
        em.detach(updatedActor);
        updatedActor
            .cname(UPDATED_CNAME)
            .ename(UPDATED_ENAME)
            .alias(UPDATED_ALIAS)
            .role(UPDATED_ROLE)
            .label(UPDATED_LABEL)
            .birthday(UPDATED_BIRTHDAY)
            .birthSite(UPDATED_BIRTH_SITE)
            .identity(UPDATED_IDENTITY)
            .gender(UPDATED_GENDER)
            .nationality(UPDATED_NATIONALITY)
            .height(UPDATED_HEIGHT)
            .bloodType(UPDATED_BLOOD_TYPE)
            .constellation(UPDATED_CONSTELLATION)
            .graduatedFor(UPDATED_GRADUATED_FOR)
            .rank(UPDATED_RANK)
            .fansCount(UPDATED_FANS_COUNT)
            .fansName(UPDATED_FANS_NAME)
            .brokerageAgency(UPDATED_BROKERAGE_AGENCY)
            .createdBy(UPDATED_CREATED_BY)
            .createdTime(UPDATED_CREATED_TIME)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY)
            .lastModifiedTime(UPDATED_LAST_MODIFIED_TIME);
        ActorDTO actorDTO = actorMapper.toDto(updatedActor);

        restActorMockMvc.perform(put("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isOk());

        // Validate the Actor in the database
        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeUpdate);
        Actor testActor = actorList.get(actorList.size() - 1);
        assertThat(testActor.getCname()).isEqualTo(UPDATED_CNAME);
        assertThat(testActor.getEname()).isEqualTo(UPDATED_ENAME);
        assertThat(testActor.getAlias()).isEqualTo(UPDATED_ALIAS);
        assertThat(testActor.getRole()).isEqualTo(UPDATED_ROLE);
        assertThat(testActor.getLabel()).isEqualTo(UPDATED_LABEL);
        assertThat(testActor.getBirthday()).isEqualTo(UPDATED_BIRTHDAY);
        assertThat(testActor.getBirthSite()).isEqualTo(UPDATED_BIRTH_SITE);
        assertThat(testActor.getIdentity()).isEqualTo(UPDATED_IDENTITY);
        assertThat(testActor.getGender()).isEqualTo(UPDATED_GENDER);
        assertThat(testActor.getNationality()).isEqualTo(UPDATED_NATIONALITY);
        assertThat(testActor.getHeight()).isEqualTo(UPDATED_HEIGHT);
        assertThat(testActor.getBloodType()).isEqualTo(UPDATED_BLOOD_TYPE);
        assertThat(testActor.getConstellation()).isEqualTo(UPDATED_CONSTELLATION);
        assertThat(testActor.getGraduatedFor()).isEqualTo(UPDATED_GRADUATED_FOR);
        assertThat(testActor.getRank()).isEqualTo(UPDATED_RANK);
        assertThat(testActor.getFansCount()).isEqualTo(UPDATED_FANS_COUNT);
        assertThat(testActor.getFansName()).isEqualTo(UPDATED_FANS_NAME);
        assertThat(testActor.getBrokerageAgency()).isEqualTo(UPDATED_BROKERAGE_AGENCY);
        assertThat(testActor.getCreatedBy()).isEqualTo(UPDATED_CREATED_BY);
        assertThat(testActor.getCreatedTime()).isEqualTo(UPDATED_CREATED_TIME);
        assertThat(testActor.getLastModifiedBy()).isEqualTo(UPDATED_LAST_MODIFIED_BY);
        assertThat(testActor.getLastModifiedTime()).isEqualTo(UPDATED_LAST_MODIFIED_TIME);
    }

    @Test
    @Transactional
    public void updateNonExistingActor() throws Exception {
        int databaseSizeBeforeUpdate = actorRepository.findAll().size();

        // Create the Actor
        ActorDTO actorDTO = actorMapper.toDto(actor);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restActorMockMvc.perform(put("/api/actors")
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(actorDTO)))
            .andExpect(status().isBadRequest());

        // Validate the Actor in the database
        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteActor() throws Exception {
        // Initialize the database
        actorRepository.saveAndFlush(actor);

        int databaseSizeBeforeDelete = actorRepository.findAll().size();

        // Delete the actor
        restActorMockMvc.perform(delete("/api/actors/{id}", actor.getId())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<Actor> actorList = actorRepository.findAll();
        assertThat(actorList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
